<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-row>
        <el-col :span="24" style="text-align: right">
          <el-input size="small" style="width: 200px" class="filter-item fsc-search" placeholder="指令号-回车查询" v-model="listQuery.condition.shipmentGid" @keyup.enter.native="searchClick"></el-input>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-search" @click="searchClick">
            搜索
          </el-button>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-circle-plus-outline" @click="moreClick">更多
          </el-button>
          <el-dropdown trigger="click" :hide-on-click=false style="float: right;margin-left: 10px">
            <span class="el-dropdown-link">
              <el-button class="filter-item" size="small" type="primary" v-waves>
                选择列
                <i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-checkbox-group v-model="theadCheckVal">
                  <el-checkbox label="shipmentGid">调度指令</el-checkbox>
                  <el-checkbox label="cusOrderNo">客户订单号</el-checkbox>
                  <el-checkbox label="cusWaybillNo">客户运单号</el-checkbox>
                  <el-checkbox label="cusTransMode">客户运输模式分类</el-checkbox>
                  <el-checkbox label="vin">VIN码</el-checkbox>
                  <el-checkbox label="originLocationName">起始地</el-checkbox>
                  <el-checkbox label="destLocationName">目的地</el-checkbox>
                  <el-checkbox label="stanVehicleType">车型</el-checkbox>
                  <el-checkbox label="status">指令状态</el-checkbox>
                  <el-checkbox label="gmtCreate">调度时间</el-checkbox>
                  <el-checkbox label="shipmentType">运输指令类型</el-checkbox>
                  <el-checkbox label="serviceProviderName">分供方</el-checkbox>
                  <el-checkbox label="driverName">司机</el-checkbox>
                  <el-checkbox label="plateNo">车牌号</el-checkbox>
                  <el-checkbox label="trailerNo">挂车号</el-checkbox>
                  <el-checkbox label="boundType">出入库类型</el-checkbox>
                  <el-checkbox label="taskStatus">寻车状态</el-checkbox>
                  <el-checkbox label="taskStatus">移车状态</el-checkbox>
                  <el-checkbox label="taskStatus">提车状态</el-checkbox>
                  <el-checkbox label="inboundStatus">入库状态</el-checkbox>
                  <el-checkbox label="outboundStatus">出库状态</el-checkbox>
                  <el-checkbox label="remarks">备注</el-checkbox>
                </el-checkbox-group>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
      <div style="clean:both"></div>
    </div>

    <div :class="{'search-transition':searchFlag,h0:true,hAuto:searchFlag,'search-content':true}">
      <el-form ref="form" :model="listQuery.condition" label-width="100px" :inline="true">
        <el-form-item label=出入库类型:>
          <el-select v-model="listQuery.condition.boundType" placeholder="请选择出入库类型">
            <el-option label="入库" value="10"></el-option>
            <el-option label="出库" value="20"></el-option>
            <el-option label="移库" value="30"></el-option>
            <el-option label="其他" value="40"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=车架号:>
          <el-input type="textarea" :rows="2" style="width: 250px"
                    v-model="listQuery.condition.vin"  placeholder="请输入车架号, 以逗号来分隔"></el-input>
        </el-form-item>
        <el-form-item label=车牌号:>
          <el-input  placeholder="请输入车牌号" class="w200" clearable v-model="listQuery.condition.plateNo" ></el-input>
        </el-form-item>
        <el-form-item label=起运地:>
          <el-input  placeholder="请输入起运地" class="w200" clearable v-model="listQuery.condition.originLocationName" ></el-input>
        </el-form-item>
        <el-form-item label=目的地:>
          <el-input  placeholder="请输入目的地" class="w200" clearable v-model="listQuery.condition.destLocationName" ></el-input>
        </el-form-item>
        <el-form-item label="调度时间:">
          <el-date-picker class="w200" v-model="listQuery.condition.startDate" type="datetime" placeholder="选择日期时间"  value-format="yyyy-MM-dd HH:mm:ss"
                          align="right" :picker-options="timePicker"></el-date-picker>
          <span style="padding: 0 6px">至</span>
          <el-date-picker class="w200" v-model="listQuery.condition.endDate" type="datetime" placeholder="选择日期时间"  value-format="yyyy-MM-dd HH:mm:ss"
                          align="right" :picker-options="timePicker"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchClick" style="margin-left: 10px">查询</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="clean:both"></div>
    <el-table ref="expectionTable" :data="shipmentList" v-loading="listLoading" element-loading-text="加载中" border fit highlight-current-row style="width: 100%;margin-top:5px">
      <el-table-column type="selection" width="35"></el-table-column>
      <el-table-column :key="key" align="center" :width="value.width" v-for='(value,key) in tableThead' :label="value.title">
        <template slot-scope="scope">
          <div v-if="value.key === 'status'">{{scope.row[value.key] | releaseStatusFilter}}</div>
          <div v-else-if="value.key === 'boundType'">{{scope.row[value.key] | boundTypeFilter}}</div>
          <div v-else-if="value.key === 'searchStatus'">{{scope.row[value.key] | taskStatusFilter}}</div>
          <div v-else-if="value.key === 'moveStatus'">{{scope.row[value.key] | taskStatusFilter}}</div>
          <div v-else-if="value.key === 'pickStatus'">{{scope.row[value.key] | taskStatusFilter}}</div>
          <div v-else-if="value.key === 'inboundStatus'">{{scope.row[value.key] | inboundLineStatusFilter}}</div>
          <div v-else-if="value.key === 'outboundStatus'">{{scope.row[value.key] | noticeLineStatusFilter}}</div>
          <div v-else>{{scope.row[value.key]}}</div>
        </template>
      </el-table-column>
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.current" :page-sizes="[10,20,30,50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="listQuery.total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import * as shipmentAPI from '@/api/pick/shipment'
  import waves from '@/directive/waves' // 水波纹指令
  const defautlTableThead = [
    { key: 'shipmentGid', title: '调度指令', width: 106 },
    { key: 'cusOrderNo', title: '客户订单号', width: 106 },
    { key: 'cusWaybillNo', title: '客户运单号', width: 106 },
    { key: 'cusTransMode', title: '客户运输模式分类', width: 106 },
    { key: 'vin', title: 'VIN码', width: 160 },
    { key: 'originLocationName', title: '起运地', width: 160 },
    { key: 'destLocationName', title: '目的地', width: 160 },
    { key: 'stanVehicleType', title: '车型', width: 160 },
    { key: 'status', title: '指令状态', width: 106 },
    { key: 'gmtCreate', title: '调度时间', width: 140 },
    { key: 'shipmentType', title: '运输指令类型', width: 106 },
    { key: 'serviceProviderName', title: '分供方', width: 106 },
    { key: 'driverName', title: '司机', width: 106 },
    { key: 'plateNo', title: '车牌号', width: 106 },
    { key: 'trailerNo', title: '挂车号', width: 106 },
    { key: 'boundType', title: '出入库类型', width: 106 },
    { key: 'searchStatus', title: '寻车状态', width: 106 },
    { key: 'moveStatus', title: '移车状态', width: 106 },
    { key: 'pickStatus', title: '提车状态', width: 106 },
    { key: 'inboundStatus', title: '入库状态', width: 106 },
    { key: 'outboundStatus', title: '出库状态', width: 106 },
    { key: 'remarks', title: '备注', width: 106 }
  ]
  export default {
    name: 'task',
    directives: {
      waves
    },
    data() {
      return {
        theadCheckVal: [
          'shipmentGid',
          'cusOrderNo',
          'cusWaybillNo',
          'cusTransMode',
          'vin',
          'originLocationName',
          'destLocationName',
          'stanVehicleType',
          'status',
          'gmtCreate',
          'shipmentType',
          'serviceProviderName',
          'driverName',
          'plateNo',
          'trailerNo',
          'boundType',
          'searchStatus',
          'moveStatus',
          'pickStatus',
          'inboundStatus',
          'outboundStatus',
          'remarks'
        ],
        tableThead: defautlTableThead,
        listQuery: {
          current: 1,
          size: 10,
          total: 0,
          condition: {}
        },
        shipmentList: [],
        listLoading: true,
        searchFlag: false,
        timePicker: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            }
          }]
        }
      }
    },
    created() {
      this.list()
    },
    watch: {
      theadCheckVal(valArr) {
        this.tableThead = defautlTableThead.filter(v => {
          for (var i = 0; i < valArr.length; i++) {
            if (v.key === valArr[i]) {
              return v
            }
          }
        })
      }
    },
    methods: {
      list() {
        // 列表查询
        this.listLoading = true
        // 处理是否展开更多
        let queryParam = {}
        if (this.$data.searchFlag) {
          queryParam = this.$data.listQuery
        } else {
          Object.assign(queryParam, this.$data.listQuery)
          queryParam.condition = {
            shipmentGid: this.$data.listQuery.condition.shipmentGid
          }
        }
        // queryParam.condition.houseId = this.$store.getters.currentStorehouse.id
        shipmentAPI.getShipmentList(queryParam).then(result => {
          if (result.code === 0) {
            this.$data.shipmentList = result.data.records
            this.$data.listQuery.total = result.data.total
            this.listLoading = false
          } else {
            this.listLoading = false
            this.$notify({
              title: '信息提示',
              message: result.message,
              type: 'error',
              duration: 2000
            })
          }
        })
      },
      handleSizeChange(val) {
        // 分页size变化
        this.$data.listQuery.size = val
        this.list()
      },
      handleCurrentChange(val) {
        // 分页当前页变化
        this.$data.listQuery.current = val
        this.list()
      },
      moreClick() {
        // 更多click
        this.$data.searchFlag = !this.$data.searchFlag
      },
      searchClick() {
        // 搜索
        this.list()
      },
      reset() {
        this.$data.listQuery.condition = {
          // houseId: this.$store.getters.currentStorehouse.id,
          vin: null,
          boundType: null,
          plateNo: null,
          originLocationName: null,
          destLocationName: null
          // startDate: null,
          // endDate: null
        }
        this.list()
      }
    }
  }
</script>
<style scoped>

</style>
